//
//  Config.swift
//  decoration_enterprise
//
//  Created by 计海峰 on 2019/9/5.
//  Copyright © 2019 Mac. All rights reserved.
//

import Foundation
import SwiftyBeaver  // 日志
import Hue
import CooperSwift
import IQKeyboardManager


//MARK: - log
//let log = SwiftyBeaver.self

class AppConfig {
    
    static func awake() {
        
        UIApplication.awake()
        
        CooperSwift.config()
        
        // 主题
        configTheme()
        
    }
    
    static func configTheme() {
        // 配置主题
        AppConfig.setupTabBarItemTheme()
        AppConfig.setupBarButtonItemTheme()
        AppConfig.setupNavigationBarTheme()
    }

    // MARK: - 设置UITabBarItem的主题
    static func setupTabBarItemTheme() {
        let appearance = UITabBarItem.appearance()
        //normal
        appearance.setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor :  theme.tabbarTheme.titleColor,
            NSAttributedString.Key.font : theme.tabbarTheme.titleFont],
                                          for: .normal)
        
        appearance.setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor : theme.tabbarTheme.selectedTitleColor,
            NSAttributedString.Key.font : theme.tabbarTheme.selectedTitleFont],
                                          for: .selected)
        
        UITabBar.appearance().backgroundColor = UIColor.white
        UITabBar.appearance().backgroundImage = UIImage()
    }

    // MARK: - 设置UIBarButtonItem的主题
    static func setupBarButtonItemTheme() {
        let appearance = UIBarButtonItem.appearance()
        
        appearance.setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor : theme.navbarTheme.barButtonTitleColor,
            NSAttributedString.Key.font : theme.navbarTheme.barButtonTitleFont],
                                          for: .normal)
        
        appearance.setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor : theme.navbarTheme.barButtonTitleColor,
            NSAttributedString.Key.font : theme.navbarTheme.barButtonTitleFont],
                                          for: .highlighted)
        
        appearance.setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor : theme.navbarTheme.barButtonDisabledTitleColor,
            NSAttributedString.Key.font : theme.navbarTheme.barButtonTitleFont],
                                          for: .disabled)
    }
    
    // MARK: - 设置UINavigationBar的主题
    static func setupNavigationBarTheme() {
        
        /// 标准
        let appearance = UINavigationBar.appearance()
        appearance.setBackgroundImage(theme.navbarTheme.backgroundColor.image(frame: CGRect.init(x: 0, y: 0, width: Screen.width, height: Screen.statusBarHeight + 44)), for: .default)
        
        let shadow = NSShadow.init()
        shadow.shadowColor = theme.navbarTheme.backgroundColor
        appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.navbarTheme.titleColor,
                                          NSAttributedString.Key.font: theme.navbarTheme.titleFont,
                                          NSAttributedString.Key.shadow: shadow]
        /// iOS15 滚动
        if #available(iOS 15.0, *) {
            let scrollAppearance = UINavigationBarAppearance()
            scrollAppearance.backgroundColor = theme.navbarTheme.backgroundColor
            scrollAppearance.shadowColor = theme.navbarTheme.backgroundColor
            scrollAppearance.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor :  theme.tabbarTheme.titleColor,
                NSAttributedString.Key.font : theme.tabbarTheme.titleFont]
            appearance.standardAppearance = scrollAppearance
            appearance.scrollEdgeAppearance = scrollAppearance
        }
        
        
    }
    
}

